package com.example.springboot.utils;

import java.time.Duration;
import java.time.LocalDateTime;

public class TimeUtil {

    public static String createRelative(LocalDateTime localDateTime) {
        Duration duration = Duration.between(localDateTime,LocalDateTime.now());
        if (duration.toDays() < 1) {
            if (duration.toHours() < 1) {
                if (duration.toMinutes() < 1) {
                    return duration.toSeconds() + "秒前";
                }
                else {
                    return duration.toMinutes() + "分钟前";
                }
            }
            else {
                return duration.toHours() + "小时前";
            }
        }
        else {
            return localDateTime.toLocalDate().toString();
        }
    }
}
